package cn.kgm.factory;

import cn.kgm.enums.ShapeEnums;
import cn.kgm.factory.shape.Circle;
import cn.kgm.factory.shape.Rectangle;
import cn.kgm.factory.shape.Shape;
import cn.kgm.factory.shape.Square;

public class ShapeFactory {

    public static Shape shapeBuilder(String type) {
        Shape shape = null;
        switch (type) {
            case "Circle":
                shape = new Circle();
                break;
            case "Rectangle":
                shape = new Rectangle();
                break;
            case "Square":
                shape = new Square();
                break;
            default:
                return shape;
        }
        return shape;
    }

    public static Shape shapeBuilderByEnum(String type) {
        Shape shape = null;
        try {
            switch (ShapeEnums.getByType(type)) {
                case CIRCLE:
                    shape = new Circle();
                    break;
                case RECTANGLE:
                    shape = new Rectangle();
                    break;
                case SQUARE:
                    shape = new Square();
                    break;
                default:
                    return shape;
            }
            return shape;
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return null;
    }
}
